<?
	include("koneksi.php");
	$nrp=$_GET['nrp'];
	$kode=$_GET['kode_mk'];
	$queri1=mysql_query("select * from penawaran where kodemk='$kode'");
	$row=mysql_fetch_row($queri1);
	$queri3=mysql_query("select sks from mk where kodemk='$kode'");
	$array=mysql_fetch_array($queri3);
	$tahun=date(Y);
	$bulan=date(m);
	$tgl=date(d);
	$savetanggal=$tahun.'-'.$bulan.'-'.$tgl;
	$jam=date(H);
	$jam2=$jam-01;
	$menit=date(i);
	$waktu=$jam2.$menit.'00';
	$queri5=mysql_query("select count(*) from registrasi where nrp='$nrp' and kodemk='$kode'");
	$row5= mysql_fetch_row($queri5);
	$queri4=mysql_query("select * from security where username='$nrp'");
	$row4=mysql_fetch_row($queri4);
	$queristatus=mysql_query("select count(*) from krs where nrp='$nrp' and kodemk='$kode'");
	$rowstatus=mysql_fetch_row($queristatus);
	//$queri2=mysql_query("insert into registrasi values('$nrp','$kode','$row[3]','','$row[5]','$savetanggal','$waktu','','$row[7]','$row[8]','$row[9]','','$array[0]') ");
	//echo "nrp=$nrp & kode=$kode & row3=$row3[0]";
	if($rowstatus[0] == 0)
	{
		if($row5[0] == 0)
		{
			$queri2=mysql_query("insert into registrasi values('$nrp','$kode','$row[3]','BARU','$row[5]','$savetanggal','$waktu','','$row[7]','$row[8]','$row[9]','','$array[0]') ");
			if($queri2)
			{
				//echo "$row4[3]-$array[0]";
				$sks = $row4[3]-$array[0];
				//echo "jumlah sks $sks <br>";
				if($sks >= 0 )
				{
					$queri6=mysql_query("update security set sks='$sks' where username='$nrp'");
					echo "Pendaftaran Berhasil";
				}
				else
				{
					echo "Maaf, limit sks anda sudah habis";
				}
			}
			else
			{
				echo "Maaf, pendaftaran gagal";
			}
		
		}
		else
		{
			echo "Maaf, anda telah terdaftar";
		}
	}
	else
	{
		if($row5[0] == 0)
		{
			$queri2=mysql_query("insert into registrasi values('$nrp','$kode','$row[3]','ULANG','$row[5]','$savetanggal','$waktu','','$row[7]','$row[8]','$row[9]','','$array[0]') ");
			if($queri2)
			{
				//echo "$row4[3]-$array[0]";
				$sks = $row4[3]-$array[0];
				//echo "jumlah sks $sks <br>";
				if($sks >= 0 )
				{
					$queri6=mysql_query("update security set sks='$sks' where username='$nrp'");
					echo "Pendaftaran Berhasil";
				}
				else
				{
					echo "Maaf, limit sks anda sudah habis";
				}
			}
			else
			{
				echo "Maaf, pendaftaran gagal";
			}
		
		}
		else
		{
			echo "Maaf, anda telah terdaftar";
		}
	}
	
?>